﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("YUIAspNet");

YUIAspNet.ColorPicker = function(element) {
    YUIAspNet.ColorPicker.initializeBase(this, [element]);
}

YUIAspNet.ColorPicker.prototype = {
    initialize: function() {
        YUIAspNet.ColorPicker.callBaseMethod(this, 'initialize');
    },

    initializeYUIControl: function(sender, args) {
        var Event = YAHOO.util.Event;
        this._yuiControl
	        = new YAHOO.widget.ColorPicker(this.get_id(),
	            {
	                showcontrols: this.get_ShowControls(),
	                showhsvcontrols: this.get_ShowHsvControls(),
	                showhexcontrols: this.get_ShowHexControls(),
	                showhexsummary: this.get_ShowHexSummary(),
	                showrgbcontrols: this.get_ShowRgbControls(),
	                showwebsafe: this.get_ShowWebsafe(),
	                red: this.get_Red(),
	                green: this.get_Green(),
	                blue: this.get_Blue(),
	                images: {
	                    PICKER_THUMB: this.get_PickerThumbImageUrl(),
	                    HUE_THUMB: this.get_HueThumbImageUrl()
	                }
	            });

        //a listener for logging RGB color changes; 
        //this will only be visible if logger is enabled: 

        var persister = $get(this.get_ColorPersister());

        var onRgbChange = function(o) {
            persister.value = o.newValue.join('|');
        };

        if (this._events) {
            var handler = this._events.getHandler("OnChange");
            var me = this;
            if (handler) {
                onRgbChange = function(o) {
                    persister.value = o.newValue.join('|');
                    handler(me, {newValue: o.newValue, oldValue: o.oldValue});
                }
            }
        }

        //subscribe to the rgbChange event;
        this._yuiControl.on("rgbChange", onRgbChange);
    },

    dispose: function() {
        //Add custom dispose actions here
        YUIAspNet.ColorPicker.callBaseMethod(this, 'dispose');
    },

    get_PickerThumbImageUrl: function() {
        return this._pickerThumbImageUrl;
    },
    set_PickerThumbImageUrl: function(pickerThumbImageUrl) {
        this._pickerThumbImageUrl = pickerThumbImageUrl;
    },

    get_HueThumbImageUrl: function() {
        return this._hueThumbImageUrl;
    },
    set_HueThumbImageUrl: function(hueThumbImageUrl) {
        this._hueThumbImageUrl = hueThumbImageUrl;
    },

    get_ShowControls: function() {
        return this._showControls;
    },
    set_ShowControls: function(showControls) {
        this._showControls = showControls;
    },

    get_ShowHexControls: function() {
        return this._showHexControls;
    },
    set_ShowHexControls: function(showHexControls) {
        this._showHexControls = showHexControls;
    },

    get_ShowHexSummary: function() {
        return this._showHexSummary;
    },
    set_ShowHexSummary: function(showHexSummary) {
        this._showHexSummary = showHexSummary;
    },

    get_ShowHsvControls: function() {
        return this._showHsvControls;
    },
    set_ShowHsvControls: function(showHsvControls) {
        this._showHsvControls = showHsvControls;
    },

    get_ShowRgbControls: function() {
        return this._showRgbControls;
    },
    set_ShowRgbControls: function(showRgbControls) {
        this._showRgbControls = showRgbControls;
    },

    get_ShowWebsafe: function() {
        return this._showWebsafe;
    },
    set_ShowWebsafe: function(showWebsafe) {
        this._showWebsafe = showWebsafe;
    },

    get_Red: function() {
        return this._red;
    },
    set_Red: function(red) {
        this._red = red;
    },

    get_Green: function() {
        return this._green;
    },
    set_Green: function(green) {
        this._green = green;
    },

    get_Blue: function() {
        return this._blue;
    },
    set_Blue: function(blue) {
        this._blue = blue;
    },

    get_ColorPersister: function() {
        return this._colorPersister;
    },
    set_ColorPersister: function(colorPersister) {
        this._colorPersister = colorPersister;
    },

    add_OnChange: function(handler) {
        this.get_events().addHandler("OnChange", handler);
    },
    remove_OnChange: function(handler) {
        this.get_events().removeHandler("OnChange", handler);
    }
}

YUIAspNet.ColorPicker.registerClass('YUIAspNet.ColorPicker', YUIAspNet.BaseControl);
